<template>
  <div class="GL_container">
    <template v-if="typeP=='importT'">
      <ImportTM @is_show_model="isShowModel" @fanHu="fanHu" :tm_count="tm_count" :t_used_num="t_used_num" :t_num="t_num"></ImportTM>
      <Modal
        :mask-closable="false"
        class="boxLbb"
        v-model="modal1"
        title="一键导入"
        class-name="vertical-center-modal"
        :footer-hide="true"
        @on-visible-change="vxU"
      >
        <div>
          <div class="marginB5">请输入代理机构名称：</div>
          <Input class="marginB20" v-model="agent_name" ref="agent_name" size="large" clearable></Input>
          
          <div class="c999">
            温馨提示：
            <div>1、因为数据庞大，请10分钟后再查看导入结果。</div>
            <div>2、本功能仅针对商标代理机构。</div>
          </div>
          <div class="textRight marginT5">
            <Button type="primary" @click="iWxo(1)">确 定</Button>
          </div>
        </div>
      </Modal>
      <Modal
        :mask-closable="false"
        class="boxLbb"
        v-model="modal2"
        title="添加单个商标"
        class-name="vertical-center-modal"
        :footer-hide="true"
        @on-visible-change="vxU"
      >
        <div>
          <div class="marginB5">请输入注册号/申请号</div>
          <div class="marginB20">
            <Input size="large" clearable placeholder="请输入注册号/申请号" v-model="register_number" ref="register_number"></Input>
          </div>
          
          <div class="textRight ">
            <Button type="primary" @click="importByRegisterNum">确 定</Button>
          </div>
        </div>
      </Modal>
      <Modal
        :mask-closable="false"
        class="boxLbb"
        v-model="modal3"
        title="以申请人名称导入"
        class-name="vertical-center-modal"
        :footer-hide="true"
        @on-visible-change="vxU"
      >
        <div>
          <div class="marginB5">请输入申请人名称</div>
          <div class="marginB10">
            <Input size="large" clearable placeholder="请输入关键词，按回车搜索" @on-enter="queryRegPeople" v-model="reg_people_name" ref="reg_people_name"></Input>
          </div>

          <ul class="tableXe " >
            <li v-for="(val,i) in reg_people_names" :key="'tmR'+i" @click="selectName(1,val)" class="pointer">{{val}}</li>
          </ul>
        </div>
      </Modal>
      <Modal
        :mask-closable="false"
        class="boxLbb"
        width="300"
        :footer-hide="true"
        v-model="modal4"
        title="批量导入"
        class-name="vertical-center-modal"
        @on-visible-change="vxU"
      >
        <div class="clearfix textCenter">
          <div class="inlineBlock marginR10" style="width:110px;height:38px">
            <Button
              type="info"
              class="marginR10"
              size="large"
              @click="$app.openWindow('static/word/商标管理-导入模板.xlsx')"
            >
              <i class="iconfont iconxiazai marginR5"></i>下载模板
            </Button>
          </div>
          <div class="inlineBlock relative" style="width:110px;height:38px">
            <Button type="primary" size="large">
              <i class="iconfont iconwenjiandaoru marginR5"></i>导入数据
            </Button>
            <input
              type="file"
              ref="wj"
              accept=".xlsx, .xls"
              class="InputFileBox margin0 padding0 width100"
              style="z-index:9;"
              @change="file_Up($event,1)"
            />
          </div>
        </div>
      </Modal>
    
    </template>
    <template v-else>
      <ImportPT @is_show_model="isShowModel" @fanHu="fanHu" :patent_count="patent_count" :t_used_num="t_used_num" :t_num="t_num"></ImportPT>
      <Modal
        :mask-closable="false"
        class="boxLbb"
        v-model="modal5"
        title="一键导入"
        class-name="vertical-center-modal"
        :footer-hide="true"
        @on-visible-change="vxU"
      >
        <div>
          <div class="marginB5">请输入代理机构名称：</div>
          <Input class="marginB20" v-model="agent_name" ref="agent_name" size="large" clearable></Input>
          
          <div class="c999">
            温馨提示：
            <div>1、因为数据庞大，请10分钟后再查看导入结果。</div>
            <div>2、本功能仅针对专利代理机构。</div>
          </div>
          <div class="textRight marginT5">
            <Button type="primary" @click="iWxo(2)">确 定</Button>
          </div>
          
        </div>
      </Modal>
      <Modal
        :mask-closable="false"
        class="boxLbb"
        v-model="modal6"
        title="添加单个专利"
        class-name="vertical-center-modal"
        :footer-hide="true"
        @on-visible-change="vxU"
      >
        <div>
          <div class="marginB5">请输入专利号</div>
          <div class="marginB20">
            <Input size="large" clearable placeholder="请输入专利号" v-model="patent_apply_number" ref="patent_apply_number"></Input>
          </div>
          
          <div class="textRight ">
            <Button type="primary" @click="importByRegisterNum_zl">确 定</Button>
          </div>

        </div>
      </Modal>


      <Modal
        :mask-closable="false"
        class="boxLbb"
        v-model="modal7"
        title="以申请人名称导入"
        class-name="vertical-center-modal"
        :footer-hide="true"
        @on-visible-change="vxU"
      >
        <div>
          <div class="marginB5">请输入申请人名称</div>
          <div class="marginB10">
            <Input size="large" clearable placeholder="请输入关键词，按回车搜索" @on-enter="queryRegPeople_zl" v-model="reg_people_name" ref="reg_people_name"></Input>
          </div>

          <ul class="tableXe " >
            <li v-for="(val,i) in reg_people_names" :key="'tmP'+i" @click="selectName(2,val)" class="pointer">{{val}}</li>
          </ul>
        </div>
      </Modal>
      

      <Modal
        :mask-closable="false"
        class="boxLbb"
        width="300"
        :footer-hide="true"
        v-model="modal8"
        title="批量导入"
        class-name="vertical-center-modal"
        @on-visible-change="vxU"
      >
        <div class="clearfix textCenter">
          <div class="inlineBlock marginR10" style="width:110px;height:38px">
            <Button
              type="info"
              class="marginR10"
              size="large"
              @click="$app.openWindow('static/word/专利管理-导入模板.xlsx')"
            >
              <i class="iconfont iconxiazai marginR5"></i>下载模板
            </Button>
          </div>
          <div class="inlineBlock relative" style="width:110px;height:38px">
            <Button type="primary" size="large">
              <i class="iconfont iconwenjiandaoru marginR5"></i>导入数据
            </Button>
            <input
              type="file"
              ref="wj"
              accept=".xlsx, .xls"
              class="InputFileBox margin0 padding0 width100"
              style="z-index:9;"
              @change="file_Up($event,2)"
            />
          </div>
        </div>
      </Modal>
    </template>



    

    
  </div>
</template>
<style lang="less">
.vertical-center-modal {
  display: flex;
  align-items: center;
  justify-content: center;

  .ivu-modal {
    top: 0;
  }
}
</style>
<script>
import ImportTM from "./_currentView/importTm";
import ImportPT from "./_currentView/importPT";

export default {
  name: "brandDo",
  components: {
    ImportTM,
    ImportPT
  },
  data() {
    let {
      $route:{
        query:{
          typeP
        }
      }
    }=this;

    let data={
      typeP,
      companyAll: {}, // 企业信息
      tm_count: {}, // 商标管理数量
      patent_count: {}, // 专利管理数量

      agent_name:'',//代理机构名称
      register_number: "", // 申请号
      patent_apply_number: "", // 专利号
      reg_people_name: "", // 申请人
      reg_people_names:[], // 申请列表

      // 头部
      t_used_num:0,//分子
      t_num:0//分母
    };
    let tool={
      // 商标4个
      modal1: false, // 默认隐藏
      modal2: false, // 默认隐藏
      modal3: false, // 默认隐藏
      modal4: false, // 默认隐藏

      // 专利4个
      modal5: false, // 默认隐藏
      modal6: false, // 默认隐藏
      modal7: false, // 默认隐藏
      modal8: false, // 默认隐藏
    };
    return Object.assign(data,tool)
  },
  watch: {
    $route(newVal,oldVal) {
      // 导入页面
      if (newVal.name == "brandDo") {
        this.iniD(); //初始化数据
      }
    },
    reg_people_name(newVal, oldVal){
      if(!$app.judgeData($app.delSpace(newVal))){
        this.reg_people_names=[];
      }
    }
  },
  methods: {
    vxU(buEr){
      if(buEr){
        this.agent_name=this.companyAll.company_name;//代理机构名称
        this.register_number='';
        this.reg_people_name='';
        this.reg_people_names=[];
        this.patent_apply_number=""; 
      }else{
      }
    },
    // 显示model
    isShowModel(num) {
      //先初始化所有数据
      // 商标4个
      this.modal1 = false;
      this.modal2 = false;
      this.modal3 = false;
      this.modal4 = false;

      // 专利4个
      this.modal5 = false;
      this.modal6 = false;
      this.modal7 = false;
      this.modal8 = false;

      this["modal" + num] = true;
    },
    // 一键导入 num：1商标，2专利
    iWxo(num) {
      let {agent_name}=this;
      if($app.judgeData($app.delSpace(agent_name))){

        if(num==1){
          $ajax.lb_getImportByAgent(agent_name, res => {
            this.modal1=false;
            $app.toast("导入成功，请10分钟后查看结果", true);
          },res=>{
            this.$refs['agent_name'].focus();
          });
        }else{
          $ajax.lb_get_importByAgent(agent_name, res => {
            this.modal5=false;
            $app.toast("导入成功，请10分钟后查看结果", true);
          },res=>{
            this.$refs['agent_name'].focus();
          });
        }
      }else{
        this.$Message.error({content:'代理机构名称，不能为空'});
        this.$refs['agent_name'].focus();
        this.agent_name='';
      }
    },

    // 申请号导入商标
    importByRegisterNum() {
      let {register_number}=this;
      if($app.judgeData($app.delSpace(register_number))){
        $ajax.lb_getImportByRegisterNum(register_number, res => {
          this.modal2=false;
          $app.toast("商标导入成功", true);
          this.huoDci();//刷新分子，分母
          this.iniD();//已管理 数量刷新
        },res=>{
          this.$refs['register_number'].focus();
        });
      }else{
        this.$Message.error({ content: "注册号/申请号，不能为空" });
        this.$refs['register_number'].focus();
        this.register_number = "";
      }
      
    },
    // 专利号导入专利
    importByRegisterNum_zl() {
      let { patent_apply_number }=this;

      if($app.judgeData($app.delSpace(patent_apply_number))){
        $ajax.lb_get_importByApplyNumber(patent_apply_number, res => {
          this.modal6=false;
          $app.toast("专利导入成功", true);
          this.huoDci();//刷新分子，分母
          this.iniD();//已管理 数量刷新
        },res=>{
          this.$refs['patent_apply_number'].focus();
        });
      }else{
        this.$Message.error({ content: "专利号，不能为空" });
        this.$refs['patent_apply_number'].focus();
        this.patent_apply_number = "";
      }
    },
    // 模糊查询申请人商标
    queryRegPeople(e) {
      let val = e.target.value;
      let { reg_people_name } = this;
      if ($app.judgeData($app.delSpace(reg_people_name))) {
        this.reg_people_names=[];
        $ajax.lb_getQueryRegPeople({
          reg_people_name: val
        },resData => {
          this.reg_people_names = resData;
        },() => {
          this.$refs['reg_people_name'].focus();
        });
      } else {
        this.$Message.error({ content: "申请人名称，不能为空" });
        this.reg_people_name = "";
      }
    },
    // 模糊查询申请人专利
    queryRegPeople_zl(e) {
      let val = e.target.value;
      let { reg_people_name } = this;
      if ($app.judgeData($app.delSpace(reg_people_name))) {
        $ajax.lb_queryApplicantOne({
          applicant_one: val
        },resData => {
          this.reg_people_names = resData;
        },() => {
          this.reg_people_name = "";
        });
      } else {
        this.$Message.error({ content: "申请人名称，不能为空" });
        this.reg_people_name = "";
      }
    },
    // 选择名字,num:1商标，2专利
    selectName(num,reg_people_name) {
      if(num==1){
        $ajax.lb_getImportByRegPeople(reg_people_name, res => {
          this.modal3=false;
          this.modal7=false;
          $app.toast("导入成功，请10分钟后查看结果", true);
        });
      }else{
        $ajax.lb_get_importByRegPeople(reg_people_name, res => {
          this.modal3=false;
          this.modal7=false;
          $app.toast("导入成功，请10分钟后查看结果", true);
        });
      }
      
    },
    // 模板导入
    file_Up(e, numWho) {
      let svr = "";
      if (numWho == 1) {
        //商标
        this.modal4 = false;
        svr = 9;
      } else {
        //专利
        this.modal8 = false;
        svr = 19;
      }

      let file = e.target.files[0]; //选中的文件

      //格式判断
      $app.suffix.excel(e, file,false, () => {
        //1营业执照,2专利文件,3身份证,4外观设计图片,5外观说明文件,6软著文件,7美术著作文件,8商标文件,
        //9商标导入文件-xls,10专利补正文件,11专利oa文件,12专利打包文件(zip/rar),13专利委托书,
        //14企业头像,15商标委托书,16商标注册个体户身份证,17商标注册企业营业执照(pdf),18专利oa时上传对照书(word)
        //19专利导入文件,20商标图片检索

        $ajax.upOther(file,svr,resData => {
            let file_path = $app.getVal_filePath(resData);

            if (numWho == 1) {
              //商标
              $ajax.lb_getImportByFile({ file_path }, res => {
                $app.toast(res.msg, true);
                this.$refs["wj"].value = "";
              });
            } else {
              //专利
              $ajax.lb_wrcRXx({ file_path }, res => {
                $app.toast(res.msg, true);
                this.$refs["wj"].value = "";
              });
            }
          },
          () => {
            this.$refs["wj"].value = "";
          }
        );
      });
    },

    iniD() {
      this.huoDci();//更新使用次数

      //获取企业信息
      $ajax.pInfo(resData => {
        this.companyAll = resData;
      });
      $ajax.lb_get_dataManageCount(null, res => {
        console.log(res);
        this.tm_count = res.data.tm_count;
        this.patent_count = res.data.patent_count;
      });
    },

    //我的资产
    huoDci(){
      let{
        typeP
      }=this;
      $ajax.wZcList(({ role_service_item_list, service_item_list }) => {
        if( typeP=='importT' && $app.judgeData(service_item_list.tm_manage)){
          this.t_used_num=service_item_list.tm_manage.used_num;
          this.t_num=service_item_list.tm_manage.num;
        }
        if( typeP=='importP' && $app.judgeData(service_item_list.patent_manage)){
          this.t_used_num=service_item_list.patent_manage.used_num;
          this.t_num=service_item_list.patent_manage.num;
        }
      });
    },
    // 关闭本页
    fanHu(){

      
      $app.closeTag(this.$route);//关闭本页
      if( this.typeP=='importT'){
        this.$router.push({
          name:'brandAdmin'
        })
      }else{
        this.$router.push({
          name:'patentAdmin'
        })
      }
      
    },

  },
  created: function() {
    this.iniD(); //初始化数据

  },
  computed: {}
};
</script>

